package com.bdqn.springweb.Controller;

import com.bdqn.springweb.Service.UserService;
import com.bdqn.springweb.pojo.User;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class UserController {
    @Resource
    private UserService userService;
    @RequestMapping(value = "/users")
    public List<User> findAllUsers() {
        List<User> list=userService.findAllUsers();
        return list;
    }
    @GetMapping(value = "/user/{id}")
    public User getUser(@PathVariable("id") Long userId) {
        User user=userService.getUer(userId);
        return user;
    }
    @PostMapping(value = "/user")
    private void addUser(User user){
        userService.addUser(user);
    }
    @PutMapping(value = "/user")
    public void updateUser(User user){
        userService.updateUser(user);
    }
    @DeleteMapping(value = "/user/{id}")
    public void deleteUser(@PathVariable("id") Long userId) {
        userService.deleteUser(userId);
    }
}
